<template>
  <div>
    <template>
      <div slot="header" class="clearfix" style="text-align: center;line-height: 30px">
        <h3>采购方案</h3>
      </div>

      <el-table
          :data="buyMessageData"
          border
          style="width: 100%">
        <el-table-column
            prop="bmSerial"
            label="采购编号">
        </el-table-column>
        <el-table-column
            prop="buynum"
            label="采购数量">
        </el-table-column>
        <el-table-column
            prop="goodsname"
            label="商品名">
        </el-table-column>
        <el-table-column
            prop="type"
            label="类型">
        </el-table-column>
        <el-table-column
            prop="standerd"
            label="规格">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="招标状态">
          <span>待采购</span>
        </el-table-column>
        <el-table-column
            fixed="right"
            label="报价审核">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="button" size="small">报价详情</el-button>
          </template>
        </el-table-column>
        <el-table-column
            fixed="right"
            label="采购完成">
          <template slot-scope="scope">
            <el-button @click="finish(scope.row)" type="button" size="small">完成</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="block">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[6, 8, 10, 12]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>

      <el-dialog
          :visible.sync="dialogVisible"
          width="45%">
        <Offer ref="child1" @closeDialog="closeWin" :bmSerial="bmSerial" :buynum="buynum" ></Offer>
      </el-dialog>

    </template>
  </div>
</template>

<script>

import Offer from "@/components/Offer";

export default {
  name: "BuyMessageOffer",
  components:{
    Offer
  },
  data(){
    return{
      pageNum: 1,
      pageSize: 6,
      total: '',
      buyMessageData:[],
      dialogVisible: false,
      bmSerial:'',
      buynum:''
    }
  },
  mounted() {
    this.init()
  },
  methods:{
    init(){
      let url = '/csc/buymessage/selectOnePageBuymessageByBidStatus/'+ this.pageNum + "/" + this.pageSize
      this.$axios.get(url).then(r=>{
        console.log(r.data)
        this.buyMessageData = r.data.list
        this.total = r.data.total
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.init()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.init()
    },
    handleClick(row){
      this.bmSerial = row.bmSerial
      this.buynum = row.buynum
      this.dialogVisible = true
      this.$refs.child1.init(this.bmSerial);
    },
    finish(row){
      console.log(row)
      this.$confirm('确定采购完成?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = '/csc/buymessage/finishBid/'+row.bmSerial
        this.$axios.get(url).then(r=>{
          this.$message.success(r.data)
          this.init()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    closeWin(){
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped>

</style>